package com.liwei.service;

import com.liwei.model.Group;
import com.liwei.model.User;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrmService {

    @Autowired
    private SessionFactory sessionFactory;


    public void count() {
        Object obj = sessionFactory.getCurrentSession().createQuery("select count(*) from Group").uniqueResult();
//        Object obj = sessionFactory.getCurrentSession().createSQLQuery("select count(*) from aa_group").uniqueResult();
        Integer count = Integer.valueOf(""+obj).intValue();
        System.out.println(count.getClass().getName()+" : "+ count);
    }

    public void test() {
        Group group = new Group();
        group.setName("技术研发部");
        sessionFactory.getCurrentSession().save(group);
        User user =new User("liwei","123456","李威威");
        user.setGroup(group);
        sessionFactory.getCurrentSession().save(user);


    }

}
